﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TaskManage.Entity;

namespace YouTrackSharp.Issues
{
    public static class IssueExtend
    {
        public static 任务 MapTo任务(this Issue issue)
        {
            任务 theTask = new 任务();
            theTask.Id = issue.Id;
            theTask.Summary = issue.Summary;
            theTask.ProjectId = "SPCloneClone";//TODO：暂时只能写死
            theTask.StartTime = issue.GetField("StartTime")?.AsDateTime().AddHours(8);
            theTask.EndTime = issue.GetField("EndTime")?.AsDateTime().AddHours(8);
            theTask.RealStartTime = issue.GetField("RealStartTime")?.AsDateTime().AddHours(8);
            theTask.RealEndTime = issue.GetField("RealEndTime")?.AsDateTime().AddHours(8);
            theTask.Progress = issue.GetField("Progress")?.AsInt32();
            theTask.预计耗时 = issue.GetField("Estimation")?.AsInt32();
            if (issue.Tags.Count > 0)
            {
                theTask.任务类型名称 = issue.Tags.First().Value;
            }

            return theTask;
        }
    }
}
